﻿using System;
using System.Windows;
using System.Windows.Interactivity;
using nRoute.Controls;
using nRoute.Navigation;
using nRoute.Samples.Netflix.ViewModels;

namespace nRoute.Samples.Netflix.Behaviors
{
    public class SearchContainerAction
        : TargetedTriggerAction<NavigationContainer> 
    {
        public static readonly DependencyProperty SearchTextProperty =
           DependencyProperty.Register("SearchText", typeof(string), typeof(SearchContainerAction),
           new PropertyMetadata(string.Empty));

        public string SearchText
        {
            get { return Convert.ToString(GetValue(SearchTextProperty)); }
            set { SetValue(SearchTextProperty, value); }
        }

        protected override void Invoke(object parameter)
        {
            if (this.Target == null || string.IsNullOrWhiteSpace(this.SearchText)) return;
            var _searchSupporter = NavigationService.GetSupporter<ISupportSearching>(this.Target);
            if (_searchSupporter != null) _searchSupporter.Search(this.SearchText);
        }        
    }
}
